<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    :maskClosable="false"
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <file-main-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit"></file-main-form>
  </j-modal>
</template>

<script>

  import FileMainForm from './FileMainForm'
  import { message } from 'ant-design-vue'
  import Vue from 'vue'
  import { ACCESS_TOKEN } from '@/store/mutation-types'
  import { deleteAction } from '@api/manage'
  export default {
    name: 'FileMainModal',
    components: {
      FileMainForm
    },
    data () {
      return {
        title:'',
        width:880,
        visible: false,
        disableSubmit: false
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        const ids_key = 'fileIds-' + Vue.ls.get(ACCESS_TOKEN);
        const info_key = 'fileInfo-' + Vue.ls.get(ACCESS_TOKEN);
        var fileInfo = localStorage.getItem(info_key);
        if(fileInfo != null){
          this.delete(fileInfo);
        }
        localStorage.removeItem(ids_key);
        localStorage.removeItem(info_key);
        this.$emit('close');
        this.visible = false;
      },
      delete(str){
        deleteAction('/file/main/true/delete_md5', {str: str});
      },
      handleOk () {
        this.$refs.realForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>